package com.mh.service;

import com.mh.dao.AppUserDAO;

import com.mh.domain.AppUser;

import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import org.springframework.transaction.annotation.Transactional;

/**
 * Spring service that handles CRUD requests for AppUser entities
 * 
 */

@Service("AppUserService")
@Transactional
public class AppUserServiceImpl implements AppUserService {

	/**
	 * DAO injected by Spring that manages AppUser entities
	 * 
	 */
	@Autowired
	private AppUserDAO appUserDAO;

	/**
	 * Instantiates a new AppUserServiceImpl.
	 *
	 */
	public AppUserServiceImpl() {
	}

	/**
	 * Load an existing AppUser entity
	 * 
	 */
	@Transactional
	public Set<AppUser> loadAppUsers() {
		return appUserDAO.findAllAppUsers();
	}

	/**
	 * Return a count of all AppUser entity
	 * 
	 */
	@Transactional
	public Integer countAppUsers() {
		return ((Long) appUserDAO.createQuerySingleResult("select count(o) from AppUser o").getSingleResult()).intValue();
	}

	/**
	 */
	@Transactional
	public AppUser findAppUserByPrimaryKey(Integer id) {
		return appUserDAO.findAppUserByPrimaryKey(id);
	}

	/**
	 * Save an existing AppUser entity
	 * 
	 */
	@Transactional
	public void saveAppUser(AppUser appuser) {
		AppUser existingAppUser = appUserDAO.findAppUserByPrimaryKey(appuser.getId());

		if (existingAppUser != null) {
			if (existingAppUser != appuser) {
				existingAppUser.setId(appuser.getId());
				existingAppUser.setUserName(appuser.getUserName());
				existingAppUser.setFullName(appuser.getFullName());
				existingAppUser.setSecretPassword(appuser.getSecretPassword());
				existingAppUser.setBirthday(appuser.getBirthday());
				existingAppUser.setEmail(appuser.getEmail());
				existingAppUser.setState(appuser.getState());
			}
			appuser = appUserDAO.store(existingAppUser);
		} else {
			appuser = appUserDAO.store(appuser);
		}
		appUserDAO.flush();
	}

	/**
	 * Delete an existing AppUser entity
	 * 
	 */
	@Transactional
	public void deleteAppUser(AppUser appuser) {
		appUserDAO.remove(appuser);
		appUserDAO.flush();
	}

	/**
	 * Return all AppUser entity
	 * 
	 */
	@Transactional
	public List<AppUser> findAllAppUsers(Integer startResult, Integer maxRows) {
		return new java.util.ArrayList<AppUser>(appUserDAO.findAllAppUsers(startResult, maxRows));
	}
	
	public List<AppUser> findAllAppUsers(AppUser appuser, Integer startResult, Integer maxRows){
		return appUserDAO.findAllAppUsers(appuser, startResult, maxRows);
				
	}
	
	public List<AppUser> findAppUser(AppUser appuser){
		return appUserDAO.findAppUser(appuser);		
	}
	
	
	
}
